import 'package:flutter/material.dart';

extension StringSize on String {
  /// 获取文字的显示高度
  double getTextHeight(TextStyle style, double maxWidth) {
    TextPainter textPainter = TextPainter(
      text: TextSpan(text: this, style: style),
      textDirection: TextDirection.ltr,
    );
    textPainter.layout(maxWidth: maxWidth);
    return textPainter.height;
  }

  /// 获取文字的显示宽度
  double getTextWidth(TextStyle style) {
    TextPainter textPainter = TextPainter(
      text: TextSpan(text: this, style: style),
      textDirection: TextDirection.ltr,
    );
    textPainter.layout();
    return textPainter.width;
  }
}
